//
//  TTDelegatesProtocol.h
//  Tint
//
//  Created by Kevin Wu on 2/22/12.
//  Copyright (c) 2012 Telligenty. All rights reserved.
//

@protocol TTDelegatesProtocol <NSObject>

- (NSArray *)delegates;
- (void)destroyDelegates;
- (id)addDelegate:(id)delegate;
- (void)removeDelegate:(id)delegate;
- (void)removeAllDelegates;

@end


#define TTSynthesizeDelegates(container) \
- (NSArray *)delegates \
{ \
  if ( container == nil ) { \
    container = TTCreateNonRetainingMutableArray(); \
  } \
  return container; \
} \
- (void)destroyDelegates \
{ \
  [container release]; \
  container = nil; \
} \
- (id)addDelegate:(id)delegate \
{ \
  NSMutableArray *delegates = (NSMutableArray *)[self delegates]; \
  return [delegates addUnidenticalObjectIfNotNil:delegate]; \
} \
- (void)removeDelegate:(id)delegate \
{ \
  NSMutableArray *delegates = (NSMutableArray *)[self delegates]; \
  [delegates removeObject:delegate]; \
} \
- (void)removeAllDelegates \
{ \
  NSMutableArray *delegates = (NSMutableArray *)[self delegates]; \
  [delegates removeAllObjects]; \
}
